home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue50 / IPC / Messages / ParentMainFormUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-31  |  1.3 KB  |  57 lines

  1. unit ParentMainFormUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Menus, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TParentForm = class(TForm)
  11.     Timer1: TTimer;
  12.     Memo1: TMemo;
  13.     MainMenu1: TMainMenu;
  14.     LaunchChildApp1: TMenuItem;
  15.     procedure LaunchChildApp1Click(Sender: TObject);
  16.   public
  17.     procedure WMCopyData(var Msg: TWMCopyData);
  18.       message wm_CopyData;
  19.   end;
  20.  
  21. {$ifdef Ver90}
  22. //This exception class did not exist until Delphi 3
  23.   EWin32Error = class(Exception);
  24. {$endif}
  25.  
  26. var
  27.   ParentForm: TParentForm;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TParentForm.LaunchChildApp1Click(Sender: TObject);
  34. const
  35.   ChildApp = 'Child.Exe';
  36. var
  37.   SI: TStartupInfo;
  38.   PI: TProcessInformation;
  39. begin
  40.   GetStartupInfo(SI);
  41.   if not CreateProcess(nil, PChar(ChildApp + ' ' + IntToStr(Handle)), nil,
  42.            nil, False, 0, nil, nil, SI, PI) then
  43.     raise EWin32Error.Create('Unable to launch ' + ChildApp);
  44. end;
  45.  
  46. procedure TParentForm.WMCopyData(var Msg: TWMCopyData);
  47. var
  48.   TextMsg: String;
  49. begin
  50.   //Set the string variable length and content to match what was sent
  51.   SetString(TextMsg, PChar(Msg.CopyDataStruct^.lpData), Msg.CopyDataStruct^.cbData);
  52.   //Put string into memo
  53.   Memo1.Text := TextMsg
  54. end;
  55.  
  56. end.
  57.